package com.alianzamedica.controllers;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.config.ExceptionConfig;

/**
 * @author Carlos
 * 
 */
public class ErrorHandler extends org.apache.struts.action.ExceptionHandler {

	@Override
	public ActionForward execute(Exception exception, ExceptionConfig config,
			ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws ServletException {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		PrintStream s = new PrintStream(baos);
		exception.printStackTrace(s);
		exception.printStackTrace();
		@SuppressWarnings("unused")
		String error = new String(baos.toByteArray());
		String mensaje = "Verifique que haya llenado todos los campos "
				+ "del formulario de manera correcta. "
				+ "Esto es posible debido a que se ha intentado "
				+ "hacer una operación ilegal, o no se ha conectado el "
				+ "sistema de manera correcta";

		request.setAttribute("mensaje", mensaje);
		String retorno = "/admin/index.do";
		request.setAttribute("linkRetorno", retorno);
		// request.setAttribute("error", error);

		return mapping.findForward("ERROR_HANDLE");
	}

}
